package com.mars.quartz.quartzdemo.demo;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author mars
 * @Description 定义业务逻辑的job
 * @Date
 * @return
 */
public class HelloJob implements Job {

    /**
     * @Author mars
     * @Description  jobExecutionContext :包含了Quartz的运行时环境以及Job本身的详细数据信息
     * @Date
     * @return
     */
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("current exec time is " + sdf.format(date));
        // 获取这个jobdetail的信息
        String jobName = jobExecutionContext.getJobDetail().getKey().getName();
        String jobGroup = jobExecutionContext.getJobDetail().getKey().getGroup();
        String jobClass = jobExecutionContext.getJobDetail().getJobClass().getName();
        System.out.println("jobName:" + jobName + ",jobGroup:" + jobGroup + ",jobClass:" + jobClass);
        // 获取这个trigger的信息
        String triggerName= jobExecutionContext.getTrigger().getKey().getName();
        String triggerGroup= jobExecutionContext.getTrigger().getKey().getGroup();
        System.out.println("triggerName:" + triggerName + ",triggerGroup:" + triggerGroup);
        // 获取schedule调度时传入的自定义参数
        Object ot1 = jobExecutionContext.getJobDetail().getJobDataMap().getString("lala");
        Object ot2 = jobExecutionContext.getJobDetail().getJobDataMap().getInt("kaka");
        Object ot3 = jobExecutionContext.getTrigger().getJobDataMap().getString("free");

        System.out.println("job other:" + ot1 + "," + ot2 );
        System.out.println("trigger other:" + ot3);
    }
}
